﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TelerikMvcApplicationASPX.Models;

namespace TelerikMvcApplicationASPX.Controllers
{
    public class UserManagerController : Controller
    {
        EntitiesTelerik entities = new EntitiesTelerik();
        //
        // GET: /UserManager/

        public ActionResult Index()
        {
            List<User> listUser = (from u in entities.Users.Include("Role")
                                        select u).ToList();
            return View(listUser);
        }

        //
        // GET: /UserManager/Details/5

        public ActionResult Details(int id)
        {
            return View();
        }

        //
        // GET: /UserManager/Create

        public ActionResult Create(User model)
        {
            model = new User();
            List<Role> listRole = (from u in entities.Roles
                                        select u).ToList();
            ViewBag.Roles = listRole;
            return View(model);
        } 

        //
        // POST: /UserManager/Create

        [HttpPost]
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
        
        //
        // GET: /UserManager/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /UserManager/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add update logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }

        //
        // GET: /UserManager/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /UserManager/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
 
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
